//
// Created by 86138 on 2025/6/8.
//

#ifndef QINGDAO_UNIVERSITY_DULINKLIST_H
#define QINGDAO_UNIVERSITY_DULINKLIST_H
#include "../01-intro/c1-1.h"
#include "../01-intro/func2-2.h"

namespace sweetcookie2 {
    typedef int ElemType;

    // 循环双链表
    typedef struct DuLNode {
        ElemType data;
        struct DuLNode *prior, *next;
    } DuLNode, *DuLinkList;

    void InitList(DuLinkList &L);

    void ClearList(DuLinkList L);

    void DestroyList(DuLinkList &L);

    Status ListEmpty(DuLinkList L);

    int ListLength(DuLinkList L);

    Status GetElem(DuLinkList L, int i, ElemType &e);

    int LocateElem(DuLinkList L, ElemType e, Status(*compare) (ElemType, ElemType));

    DuLNode* GetElemP(DuLinkList L, int i);

    Status PriorElem(DuLinkList L, ElemType cur_e, ElemType &pre_e);

    Status NextElem(DuLinkList L, ElemType cur_e, ElemType &next_e);

    void ListTraverse(DuLinkList L);

    void ListTraverseBack(DuLinkList L);

    Status ListInsert(DuLinkList L, int i, ElemType e);

    Status ListDelete(DuLinkList L, int i, ElemType &e);
}
#endif //QINGDAO_UNIVERSITY_DULINKLIST_H
